package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * @Author by 孙有泽
 * @Date 2025/3/3 21:04
 * @Description 套餐管理
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api("套餐管理")
public class SetmealController {


    @Autowired
    private SetmealService setmealService;

    /*
     * @author 孙有泽
     * @date 2025/3/3 21:40
     * @descriptionc 套餐新增
     */
    @PostMapping()
    @CacheEvict(value = "setmealCache", key ="#setmealDTO.id")
    public Result save(@RequestBody  SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/3/3 22:14
     * @description 套餐列表
     */

    @GetMapping("/page")
    public Result<PageResult> list(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResul=setmealService.list(setmealPageQueryDTO);
        return Result.success(pageResul);
    }

    /*
     * @author 孙有泽
     * @date 2025/3/3 22:22
     * @description 套餐的停售
     */
    @PostMapping("/status/{status}")
    @CacheEvict(value = "setmealCache",allEntries = true)
    public Result updateStatus(@PathVariable Integer status,@RequestParam Long id){
        setmealService.updateStatus(status,id);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/3/4 9:21
     * @description 套餐的删除
     */
    @CacheEvict(value = "setmealCache",allEntries = true)
    @DeleteMapping()
    @ApiOperation(value = "套餐批量删除")
    public Result delete(@RequestParam List<Long> ids){
        setmealService.delete(ids);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/3/5 17:43
     * @description 根据id查询套餐
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        SetmealVO setmealVO=setmealService.getById(id);

        return Result.success(setmealVO);
    }




}
